//
//  WmcDevLogCell.swift
//  YPWatermarkCamera
//
//  Created by 周诗松 on 2022/6/23.
//

import UIKit

class WmcDevLogCell: WmcBaseTableCell {
    // Internal
    
    var switchClosure: ((Bool) -> Void)?

    override func makeUI() {
        super.makeUI()

        lineView.backgroundColor = .wmc_grayH19_F5F5F5
        titleLabel.font = UIFont.systemFont(ofSize: 14, weight: .medium)

        contentView.addSubview(titleLabel)
        contentView.addSubview(switchBtn)
        contentView.addSubview(lineView)

        titleLabel.snp.makeConstraints { make in
            make.left.equalTo(25)
            make.centerY.equalToSuperview()
            make.height.equalTo(20)
        }
        
        switchBtn.snp.makeConstraints { make in
            make.right.equalTo(-12)
            make.centerY.equalToSuperview()
        }

        lineView.snp.makeConstraints { make in
            make.left.equalTo(12)
            make.right.equalTo(-12)
            make.bottom.equalToSuperview()
            make.height.equalTo(1)
        }
    }

    func bindModel(_ model: WmcDevEnvironmentVC.WmcDevLogModel) {
        titleLabel.text = model.name
        switchBtn.isOn = model.isOpen
    }
    
    private lazy var switchBtn: UISwitch = {
        let switc = UISwitch()
        switc.onTintColor = .wmc_mainTheme
        switc.addTarget(self, action: #selector(onSwitchAction(sender:)), for: .valueChanged)
        return switc
    }()
    
    @objc func onSwitchAction(sender: UISwitch) {
        switchClosure?(sender.isOn)
    }

    override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code
    }

    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }

    
}
